<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改服务网点')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-services-edit" th:object="${jtBranchServices}">
            <input name="servicesId" th:field="*{servicesId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">[[#{serviceBranchName}]]：</label>
                    <div class="col-sm-8">
                        <input name="servicesName" th:field="*{servicesName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{region}]]：</label>

                    <div class="col-sm-8">
                        <div class="radio-box" th:each="item : ${countryCodeList}">
                            <input type="radio" th:id="${item.countryCode}" name="countryRegion" th:value="${item.countryRegion}" th:checked="${jtBranchServices.countryRegion == item.countryRegion}">
                            <label th:for="${item.countryCode}" th:text="${item.countryRegion}"></label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">[[#{phoneNumber}]]：</label>
                    <div class="col-sm-8">
                        <input name="countryCode" th:field="*{countryCode}" class="input-line" type="number" maxlength="5" style="width: 70px;" th:placeholder="#{countryCode}" readonly>
                        <span>-</span>
                        <input name="phone" th:field="*{phone}" class="input-line" type="number" maxlength="11" style="width: 120px;" th:placeholder="#{phoneNumber}" >
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{email}]]：</label>
                    <div class="col-sm-8">
                        <input name="email" th:field="*{email}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{image}]]：</label>
                    <div class="col-sm-8">
                        <div class="fileinput fileinput-new" data-provides="fileinput">
                            <div class="fileinput-new thumbnail" style="width: 120px;">
                                <img th:src="*{imageUrl}">
                            </div>
                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 450px;"></div>
                            <div>
                                <span class="btn btn-white btn-file"><span class="fileinput-new">[[#{select.img}]]</span><span class="fileinput-exists">[[#{change}]]</span>
                                <input type="file" id="img-file" accept="image/*"></span>
                                <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">[[#{clear}]]</a>
                            </div>
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>[[#{suggest.img.size}]]</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{detailedAddress}]]：</label>
                    <div class="col-sm-8">
                        <textarea name="address" class="form-control" rows="3">[[*{address}]]</textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{status}]]：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                            <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                            <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/services";
        $("#form-services-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                //$.operate.save(prefix + "/edit", $('#form-services-edit').serialize());

                submitData(prefix + "/edit", $('#form-services-edit').serializeObject(), 1);
            }
        }

        function submitData(url, formData, type) {
            var file = $('#img-file')[0].files[0];

            if (file != undefined) {
                $.modal.alertWarning(i18n("select.img"));
                var fileSize = parseInt(file.size / 1024); //KB
                if (fileSize > 1024 * 5) {
                    var sizeTips = i18n("select.img.size");
                    $.modal.alertWarning(sizeTips.replace("{0}", fileSize));
                    return;
                }
            }
            formData.append('file', file);

            $.ajax({
                url: url,
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    if(1 == type) {
                        $.operate.successCallback(result);
                    } else {
                        //提交后不刷新清空；
                        if (result && result.code == 0) {
                            $.modal.msgSuccess(result.msg);
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    }
                }
            });
        }

        $.fn.serializeObject = function()
        {
            var o = new FormData();
            var formArray = this.serializeArray();
            $.each(formArray, function() {
                o.append(this.name+'', (this.value || ''));
            });
            return o;
        };


        $('input[name="countryRegion"]').change(function() {
            if ($(this).is(':checked')) {
                var v = $(this).attr("id");
                console.log('选中的值是: ' + v);
                $('input[name="countryCode"]').val(v);
            }
        });
    </script>

    <script th:inline="javascript">
        var ROOT = [[${#servletContext.contextPath}]];
        var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

        //初始化i18n
        $.i18n.properties({
            path: ROOT + '/i18n/',//这里表示访问路径
            name: 'messages',//文件名开头
            language: LANG_COUNTRY,//文件名语言 例如en_US
            mode: 'map'//默认值
        });

        //i18n函数
        function i18n(msgKey) {
            try {
                return $.i18n.prop(msgKey);
            } catch (e) {
                return msgKey;
            }
        }
    </script>
</body>
</html>